function [res,res_cor,all_res_cor]=meta_analysis_get_cell_types(proj_meta,cur_site)

order={};
exp_inds={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    nbr_frames=proj_meta(cur_site).rd(1,tnd).nbr_frames;
    if length(nbr_frames)>5
        for xnd=1:length(nbr_frames)
            if nbr_frames(xnd)==5000
                if xnd==length(nbr_frames)
                    order{tnd}(xnd)=3;
                else
                    order{tnd}(xnd)=1;
                end
            else
                order{tnd}(xnd)=2;
            end
        end
        ord_ind=1:length(order{tnd});
        order{tnd}(max(ord_ind(order{tnd}==2))+1:end)=3;
    else
        order{tnd}=[1 2 1 2 3];
    end
    exp_inds{tnd}(1,1)=1;
    exp_inds{tnd}(1,2)=nbr_frames(1);
    for fnd=2:length(order{tnd})
        exp_inds{tnd}(fnd,1)=exp_inds{tnd}(fnd-1,2)+1;
        exp_inds{tnd}(fnd,2)=sum(nbr_frames(1:fnd));
    end
end

[shad,vis_fl,pert_num]=meta_analysis_get_vars(proj_meta,cur_site,order,exp_inds);
[blink_snips,blink_snips_dark,eye_snips,eye_snips_dark]=meta_analysis_eye_onset(proj_meta,cur_site,order,exp_inds);

all_act={};
pl_cells=[];
% mean_fluo=[];
for tnd=1:size(proj_meta(cur_site).rd,2)
    cnt=0;
    for vnd=1:size(proj_meta(cur_site).rd,1)
        all_act{tnd}(cnt+1:cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1),:)=proj_meta(cur_site).rd(vnd,tnd).act;
%         mean_fluo(cnt+1:cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1),tnd)=mean(proj_meta(cur_site).rd(vnd,tnd).act,2);
        cnt=cnt+size(proj_meta(cur_site).rd(vnd,tnd).act,1);
        pl_cells(vnd)=cnt;
    end
end

blink_light={};
blink_dark={};
eye_light={};
eye_dark={};
for gnd=1:size(proj_meta(cur_site).rd,2)
    light=sum(proj_meta(cur_site).rd(1,gnd).nbr_frames(order{gnd}~=3));
    dark=sum(proj_meta(cur_site).rd(1,gnd).nbr_frames(order{gnd}==3));
    if sum([light,dark])~=sum(proj_meta(cur_site).rd(1,gnd).nbr_frames)
        error('Wrong nbr_frames for light/dark')
    end
    blink_light{gnd}=zeros(1,light);
    blink_dark{gnd}=zeros(1,dark);
    eye_light{gnd}=zeros(1,light);
    eye_dark{gnd}=zeros(1,dark);
    for hnd=1:size(blink_snips{gnd},1)
        blink_light{gnd}(mean(blink_snips{gnd}(hnd,:))-1:mean(blink_snips{gnd}(hnd,:))+1)=1;
    end
    for hnd=1:size(blink_snips_dark{gnd},1)
        blink_dark{gnd}(mean(blink_snips_dark{gnd}(hnd,:))-1:mean(blink_snips_dark{gnd}(hnd,:))+1)=1;
    end
    for hnd=1:size(eye_snips{gnd},1)
        eye_light{gnd}(mean(eye_snips{gnd}(hnd,:))-1:mean(eye_snips{gnd}(hnd,:))+1)=1;
    end
    for hnd=1:size(eye_snips_dark{gnd},1)
        eye_dark{gnd}(mean(eye_snips_dark{gnd}(hnd,:))-1:mean(eye_snips_dark{gnd}(hnd,:))+1)=1;
    end
end

blink_whole={};
eye_whole={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    blink_whole{tnd}=blink_light{tnd};
    blink_whole{tnd}(end+1:end+length(blink_dark{tnd}))=blink_dark{tnd};
    eye_whole{tnd}=eye_light{tnd};
    eye_whole{tnd}(end+1:end+length(eye_dark{tnd}))=eye_dark{tnd};
end

res=[];
res_cor=[];
all_res_cor={};
dig=0:46;
dig(41)=[];
dig(24)=[];
dig(10)=[];
for gnd=1:size(proj_meta(cur_site).rd,2)
    mats=[];
    nums=[];
    light=sum(proj_meta(cur_site).rd(1,gnd).nbr_frames(order{gnd}~=3));
    dark=sum(proj_meta(cur_site).rd(1,gnd).nbr_frames(order{gnd}==3))-1;
    runM=proj_meta(cur_site).rd(1,gnd).velM_smoothed>0.01;
    runM_light=runM(1:light);
    runM_dark=runM(end-dark:end);
    for tnd=1:size(all_act{gnd},1)
        %shad 1-44
        cnt=1;
        for knd=1:length(dig);
            if sum(shad{gnd}==dig(knd))~=0
                mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(shad{gnd}==dig(knd))')^2;
            else
                mats(tnd,cnt)=NaN;
            end
            cnt=cnt+1;
        end
        %feedback_all
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(shad{gnd}==1|shad{gnd}==31)')^2;
        cnt=cnt+1;
        %FFM_all
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(shad{gnd}==2|shad{gnd}==32|shad{gnd}==33)')^2;
        cnt=cnt+1;
        %LFM_all
        for knd=1:12
            mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(shad{gnd}==dig(knd+3)|shad{gnd}==dig(knd+32))')^2;
            cnt=cnt+1;
        end
        %visual_flow
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',vis_fl{gnd}')^2;
        cnt=cnt+1;
        %not visual_flow
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(~vis_fl{gnd})')^2;
        cnt=cnt+1;
        %running_light
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,1:light)',runM_light')^2;
        cnt=cnt+1;
        %blink_light
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,1:light)',blink_light{gnd}')^2;
        cnt=cnt+1;
        %eye_light
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,1:light)',eye_light{gnd}')^2;
        cnt=cnt+1;
        %running whole
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',runM')^2;
        cnt=cnt+1;
        %not running_whole
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',(~runM)')^2;
        cnt=cnt+1;
        %blink_whole
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',blink_whole{gnd}')^2;
        cnt=cnt+1;
        %eye_whole
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,:)',eye_whole{gnd}')^2;
        cnt=cnt+1;
        %running in dark
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,end-dark:end)',runM_dark')^2;
        cnt=cnt+1;
        %blink_dark
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,end-dark:end)',blink_dark{gnd}')^2;
        cnt=cnt+1;
        %eye_dark
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,end-dark:end)',eye_dark{gnd}')^2;
        cnt=cnt+1;
        %line of zeros
        mats(tnd,cnt)=corr(all_act{gnd}(tnd,end-dark:end)',zeros(1,size(eye_dark{gnd},2))')^2;
        cnt=cnt+1;
    end
    [res_cor(:,gnd),res(:,gnd)]=max(mats,[],2);
    all_res_cor{gnd}=mats;
end